<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SplitContainer Demo</title>
     <style type="text/css">
            @import "../dojo/dojo-release-1.0.0/dijit/themes/tundra/tundra.css";
            @import "../dojo/dojo-release-1.0.0/dojo/resources/dojo.css";
            @import "../dojo/dojo-release-1.0.0/dojox/grid/_grid/tundraGrid.css";
            @import "../dojo/dojo-release-1.0.0/dojox/grid/_grid/Grid.css";
            @import "../js/wlProject.css";
            @import "../js/dijitTests.css";
	
      </style>
      <script type="text/javascript" src="../dojo/dojo-release-1.0.0/dojo/dojo.js"  
                djConfig="parseOnLoad: true, isDebug: true,locale: 'zh-cn', extraLocale: ['zh-TW', 'fr']"></script>
       <script>
            dojo.require("dijit.Menu");
            dojo.require("dojo.data.ItemFileWriteStore");
            dojo.require("dijit.layout.SplitContainer");
            dojo.require("dijit.layout.ContentPane");
            dojo.require("dijit.Tree");
            dojo.require("dojo.parser");
            dojo.require("dijit._tree.dndSource");
            dojo.require("dijit.layout.TabContainer");
            dojo.require("dijit.form.Button");
            dojo.require("dojox.grid.Grid");
            dojo.require("dojox.grid._data.model");
            dojo.require("dojo.i18n");
            dojo.require("dojox.validate._base");
            dojo.require("dijit.form.ValidationTextBox");
            dojo.require("dijit.form.TextBox");
            dojo.require("dijit.form.FilteringSelect");
            dojo.require("dojox.grid._data.dijitEditors");
            
            dojo.registerModulePath("mydojo", "../../../js/mydojo");
            dojo.require("mydojo.FilteringSelect");
            dojo.require("mydojo.ValidationTextBox");
            dojo.require("mydojo.NumberTextBox");
     </script>
        
     <script type="text/javascript" src="../js/soapclient.js"></script>
     <script type="text/javascript" src="../js/wlProject.js"></script>
     <script type="text/javascript" src="../js/handle.js"></script>
     <script type="text/javascript" >


         var url = getUrl()+ "services/RoleHandleManageService";
         var placedata =  new Array();
         var placedata2 =  new Array();
         // var querydata = new Array();
         var detailRows = [];
         
         var data =new Array();
         var poptarts ={ label:'name',identifier:'eId',items:data};
         var popStore = new dojo.data.ItemFileWriteStore({data: poptarts});
         
         
         var citySelectArray = new Array();
         var cityidSelectArray = new Array();
         var cityidSelectData = new Array();
         
 //按钮  
         var deletedata =new Array();
         var deletedata2 =new Array();
          //var itemt="区域";
         var selectNodeIdentity=0;//单击的树节点ID
         var selectNode;
          
          var griddata =  new Array();
          var deletedata=new Array();
          var querydata =  new Array();
          var queryvo=new HandleInfoVOJs(); //   
          var totalCount=0 ;
          var totalpage=0 ;
          var pagenumber=1;
          var pagesize=4;
          var model = new dojox.grid.data.Table(null, griddata);
          var editfield =[{type: 'dojox.GridRowView', width: '20px' },{
                                 cells: [ [
                                            //{name: '????', width: 3, get:getChoise},
                                           { name: 'choise', width: 3,field:0, styles: 'text-align: center;', editor: dojox.grid.editors.Bool },//
                                           { name: 'No.', width: 2, styles: 'text-align: center;', get: function(inRowIndex){ return inRowIndex+1;} },//
                                          {name: 'handleSno', field: 2,width: 10 , editor: mydojo.ValidationTextBox ,required:true ,maxLength:30,invalidMessage:'can not be empty'}
                                             ,   {name: 'handleName', field: 3,width: 10 , editor: mydojo.ValidationTextBox ,required:true ,maxLength:30,invalidMessage:'can not be empty'}
                                             ,   {name: 'programName', field: 4,width: 10 , editor: mydojo.ValidationTextBox ,required:true ,maxLength:30,invalidMessage:'can not be empty'}
                                             ,   {name: 'remark', field: 5,width: 10, editor: mydojo.ValidationTextBox , required:false ,maxLength:100,invalidMessage:'' }
                                             ,   {name: 'handleType', field: 6,width: 10, editor: mydojo.ValidationTextBox , required:false ,maxLength:100,invalidMessage:'' }
                                             ] ]
                           }];

  function call_funUpd() {
       //var s = grid.selection.getSelected();
       var  d=new DateTimeQuery();
       var n=new NumberQuery();
       var sall=grid.model.data;
       for(var i=0;i<sall.length;i++){
       if(sall[i][0]==true){
         var passAll=0;
         var thisCell=sall[i];
         var padd = new SOAPClientParameters2();
         var vobject=new HandleInfoVOJs();
         vobject.id=thisCell[1];
              if(dojox.validate.isText(thisCell[2], {minlength: 1})){vobject.handleSno=thisCell[2];
             }else{grid.getCell(2).getNode(i).innerHTML="<span style={color:red;line-height:16px}>can not be null</span>"; passAll=1;}//not null
               if(dojox.validate.isText(thisCell[3], {minlength: 1})){vobject.handleName=thisCell[3];
             }else{grid.getCell(3).getNode(i).innerHTML="<span style={color:red;line-height:16px}>can not be null</span>"; passAll=1;}//not null
               if(dojox.validate.isText(thisCell[4], {minlength: 1})){vobject.programName=thisCell[4];
             }else{grid.getCell(4).getNode(i).innerHTML="<span style={color:red;line-height:16px}>can not be null</span>"; passAll=1;}//not null
                vobject.remark=thisCell[5];
                vobject.handleType=thisCell[6];
        if(passAll==0){
             if(thisCell[1]==0){//create new row
                padd.add('HandleInfoVO',vobject);
                SOAPClient.invoke(url, "createHandleInfo", padd, false,  function GetEnu_callBack(ul, soapResponse){
                grid.model.setDatum(ul,i,1);
                });
	         }else{//modify row
                padd.add('HandleInfoVO',vobject);
                SOAPClient.invoke(url, "updateHandleInfo", padd, false,  function GetEnu_callBack(ul, soapResponse){
                });
	         }
        } }}//for
//submit delete
          for(var i=0;i<deletedata.length;i++){
               var pdel = new SOAPClientParameters();      
               pdel.add('id',deletedata[i]);
               SOAPClient.invoke(url, "deleteHandleInfo", pdel, false,  function GetEnu_callBack(ul, soapResponse){
	             
	           });
          }
          deletedata=new Array();
          dojo.byId("rowCount").innerHTML = 'saved'; 
//submit delete end          
 }

 function removeSelectedRowsGrid(){
       //var s = grid.selection.getSelected();
       var s= new Array();
       var sall=grid.model.data;
       for(var i=0;i<sall.length;i++){
       if(sall[i][0]==true){
          s.push(i);
          var thisCell=sall[i];
          if(thisCell[1]!=0){//the row which will be deleted
            deletedata.splice(deletedata.length,0,thisCell[1]);
          }
      }    
      grid.model.remove(s);//grid.removeSelectedRows();
 }}
        
addRow = function(){
          	grid.addRow([false,0,"","",""],grid.model.getRowCount());
	        } 
	        
         
function querybutton(){
              //var p = new SOAPClientParameters2();
              var d,n;
              var validstate=0;
              //queryvo.id=0 ;
              queryvo=new HandleInfoVOJs();
              if(queryhandleSno.getDisplayedValue()!="")queryvo.handleSno=queryhandleSno.getDisplayedValue();//
              if(queryhandleName.getDisplayedValue()!="")queryvo.handleName=queryhandleName.getDisplayedValue();//
              if(queryprogramName.getDisplayedValue()!="")queryvo.programName=queryprogramName.getDisplayedValue();//
              if(queryremark.getDisplayedValue()!="")queryvo.remark=queryremark.getDisplayedValue();//
              if(queryhandleType.getDisplayedValue()!="")queryvo.handleType=queryhandleType.getDisplayedValue();//
        if(validstate==0){
              pagenumber=1;
              getVO(queryvo,pagenumber,pagesize,'0');
              if(totalpage>1){dijit.byId("but7").setDisabled(false);}else{dijit.byId("but7").setDisabled(true);}
             }      
       }

 querydis = function(){
               querydisplay("queryDiv");
            }
 
 


function getVO(queryvo,pagenumber,pagesize,orderBy){

      var pu = new SOAPClientParameters2();
      pu.add('HandleInfoVO',queryvo) ;
      pu.add('pageNumber',pagenumber) ;
	    pu.add('pageSize',pagesize) ;
	    pu.add('orderBy',orderBy) ;
      SOAPClient.invoke(url,"getHandleInfo", pu, false,  function GetEnu_callBack(ul, soapResponse){      
           querydata=HandleInfoVOtoArray_fun(ul,true);
           totalCount=ul[ul.length-1]["ns:id"]; 
           totalpage=Math.ceil(new Number(totalCount)/pagesize);
           document.getElementById("rowCount").innerHTML=" "+pagenumber+" / "+totalpage+" / "+totalCount+" " ;
      }); 
      querydata.splice(querydata.length-1,1);
      model.setData(querydata);
      //dijit.byId("grid").updateRowCount(querydata.length); 
 }
 var myModel = new dijit.tree.ForestStoreModel({
  				store: popStore,
  				rootId: "0",
  				rootLabel: "系统操作树",
  				childrenAttrs: ["children"]
  			});        
  var _tree=dijit.byId("tree");      
  function getTreeNodes(PeopleID,ParentSno,chitem,layerInt,layerSum){//首层layerInt=0
             var pl = new SOAPClientParameters();
             pl.add('peopleId',PeopleID) ;
             pl.add('ParentSno',ParentSno) ;
      SOAPClient.invoke(url,"getHandleByPeopleAndParentSno", pl, false,  function GetEnu_callBack(ul, soapResponse){    
               var pInfo = {
                   					parent: chitem,		
                   					attribute: "children"	
                   		};
               if(ul!=null && ul.length>0 ){
                     
                     for(var i = 0; i < ul.length; i++){		
                                  var ulo=ul[i];
                                  for(var t in ulo){
                                  console.log(t+":"+ulo[t]);
                                  }
                                  var newitem=popStore.newItem({name: ulo["ns:handleName"],type:ulo["ns:handleSno"] ,eId:ulo["ns:id"],haveChild:"0"}, pInfo);//haveChild=0初始，1有子结点，2无子结点
                                 // alert("jhjhk");
                                  if(layerInt<layerSum)getTreeNodes(PeopleID,ulo["ns:handleSno"],newitem,layerInt+1,layerSum);
                      }
                     if(chitem!=null){
                            popStore.setValue(chitem,"haveChild","1"); 
                            var node = dijit.byId("tree")._itemNodeMap[chitem.eId];
                            node._updateItemClasses(node.item);
                            //node.expand();       
                      }
                }else{
                    popStore.setValue(chitem,"haveChild","2");  
                }       
          });
        
        }
   function expandAllChildrenNode(tree,treeNode,layerInt,layerSum){
		      //treeNode.expand();
		      var childrenArray=treeNode.getChildren();
          if(childrenArray.length>0)tree._expandNode(treeNode);
          for (var i=0; i<childrenArray.length; i++){//begin	
             if(layerInt<layerSum) expandAllChildrenNode(tree,childrenArray[i],layerInt+1,layerSum);
             //if(layerInt==layerSum&&tree.model.mayHaveChildren(childrenArray[i].item))childrenArray[i].
             if(layerInt==layerSum)childrenArray[i]._updateItemClasses(childrenArray[i].item);
          }
        }              
         
function init(){
      var _tree=dijit.byId("tree");  
		    getTreeNodes(1,"",null,0,2);
		    expandAllChildrenNode(_tree,_tree.rootNode,0,1);
 
         dojo.connect(dijit.byId("tree"), "_onExpandoClick", function(message){
                       // _expandNode
                       var node = message.node;
                       var ch2node=node.getChildren();
                       for (var i=0; i<ch2node.length; i++){	
                       //alert(ch2node.length);
                       if(ch2node[i].getChildren().length==0&&ch2node[i].item.haveChild=="0"){
                         var ch2item =ch2node[i].item;
                         getTreeNodes(ch2item.eId,1,ch2item,0,1);
                       }
                      
                      }
             	 
            });   
      
//查询列表----begin
             dojo.connect(_tree, "onClick", function(item,node){
             //判断哪个tab在显示
             	      selectNode=node;
                    //selectNodeIdentity = _tree.store.getIdentity(item);
                    //placedata = new Array();
                    queryvo.handleSno=selectNode.type+"___";
					//if(selectNode.label="系统操作树")queryvo.handleSno="___";
                    getVO(queryvo,pagenumber,pagesize,"0")
                    grid.selection.clear();
                /* var titles=node.item["name"];
                var parentNodes=node;
                while(parentNodes.getParent()!= null&& parentNodes.getParent()["id"]!="tree"){
                      parentNodes=parentNodes.getParent();
                      titles=parentNodes.item["name"]+' '+titles;
                };
                dojo.byId("placetitle").innerHTML = titles +"";*/
                deletedata =new Array();
                
              
           });  
           //查询列表----end
  }//END INIT
            
           dojo.addOnLoad(init);
           

          //查询按钮
          
          
</script>
</head>
<body class="tundra">
       
	
	 <div dojoType="dijit.layout.SplitContainer"   orientation="horizontal"  sizerWidth="7" activeSizing="false"	style="border: 1px solid #bfbfbf; width: 1260px; height: 845px;"  >
		
         <div dojoType="dijit.layout.ContentPane" id="treePane"  sizeMin="20" sizeShare="20"   >
                     
                <div id="tree" showRoot="true" dojoType="dijit.Tree"  store="popStore" label="系统操作树" labelAttr="name"  childrenAttr="children"  model="myModel" ></div> 
         </div>
         
        <div dojoType="dijit.layout.ContentPane" sizeMin="50" sizeShare="50"  >
        	<div id="queryDiv" style="margin-right: 30px;  height: 460px; display:none;" >
              <table align="center" width=100% class="queryTable"  >
                <tr ><td align="center" style="{width:11%}">Please input criterial:</td>
                <td style="{width:22%}" ></td>
                <td style="{width:11%}"></td>
                <td style="{width:6%}" ></td>
                <td style="{width:11%}" ></td>
                <td style="{width:6%}" ></td>
                <td style="{width:11%}"></td>
                <td style="{width:22%}"></td></tr> 
                <tr ><td align="center" style="{width:11%}"></td>
                <td style="{width:22%}" ></td>
                <td style="{width:11%}"></td>
                <td style="{width:6%}" ></td>
                <td style="{width:11%}" ></td>
                <td style="{width:6%}" ></td>
                <td style="{width:11%}"></td>
                <td style="{width:22%}"></td></tr>  
                <tr>
                    <td align="right"  >handleSno:</td>
                    <td align="left"  ><input type="text" class="editerInput"  id="queryhandleSno"  jsId="queryhandleSno"   dojoType="dijit.form.TextBox"  /></td>
                    <td align="right"  >handleName:</td>
                    <td align="left"  colspan="3" ><input type="text" class="editerInput"  id="queryhandleName"  jsId="queryhandleName"   dojoType="dijit.form.TextBox"  /></td>  
                    <td align="right"  >programName:</td>
                    <td align="left"  ><input type="text" class="editerInput"  id="queryprogramName"  jsId="queryprogramName"   dojoType="dijit.form.TextBox"  /></td>  
              </tr>
                <tr>
                    <td align="right"  >remark:</td>
                    <td align="left"  ><input type="text" class="editerInput"  id="queryremark"  jsId="queryremark"   dojoType="dijit.form.TextBox"  /></td>
                    <td align="right"  >handleType:</td>
                    <td align="left"  colspan="3" ><input type="text" class="editerInput"  id="queryhandleType"  jsId="queryhandleType"   dojoType="dijit.form.TextBox"  /></td>  
	
          <tr align="center"><td></td>
           <td colspan="2"><a onclick="querybutton();"><img src="../image/332.gif" height="20" width="20" border="0">OK</a></td>
           <td colspan="3"></td><td colspan="2"></td></tr>
         </table>
	     </div>
	       		<div align="right">
	          	 &nbsp;&nbsp;&nbsp;
	          	     <button dojoType="dijit.form.Button" onclick="addRow();" iconClass="addIcon" >add</button>
	                 <button dojoType="dijit.form.Button" onclick="removeSelectedRowsGrid();" iconClass="delIcon" >delete</button>
	                 <button dojoType="dijit.form.Button" id="but3" jsId="but3" onclick="call_funUpd();"  iconClass="saveIcon">save</button>
	          	     <button dojoType="dijit.form.Button" onclick="querydis();" iconClass="queryIcon" >query</button>
                  
         		</div>    
	        <div id="rowCount"></div>
	    <div style="{height:90%;width:100%}"  >
	         <div id="grid"  dojoType="dojox.Grid" autoWidth="false"  jsId="grid"	model="model"  structure="editfield" singleClickEdit="true" ></div>
      </div> 
      <div align="right" ><span id="rowCount"></span>
        <button dojoType="dijit.form.myButton" onclick="upPage();"  id="but6" disabled='true' jsId="but6" iconClass="upPageIcon" >pageup</button><!--span dojoType="dijit.Tooltip" connectId="but6">pageup</span-->
        <button dojoType="dijit.form.myButton" onclick="downPage();" id="but7" disabled='true' jsId="but7" iconClass="downPageIcon" >pagedown</button><!--span dojoType="dijit.Tooltip" connectId="but7">pagedown</span-->
        <div id="668" dojoType="dijit.form.myDropDownButton" iconClass="pageIcon" ><span>pageNumber</span>
  			  <div dojoType="dijit.Menu">
				  <div dojoType="dijit.MenuItem" label="10"  iconClass="toPageIcon"		onClick="pageSizeChange(this.label);"></div>
				  <div dojoType="dijit.MenuItem"  label="30" iconClass="toPageIcon"		onClick="pageSizeChange(this.label);"></div>
		      <div dojoType="dijit.MenuItem"  label="50" iconClass="toPageIcon"		onClick="pageSizeChange(this.label);"></div>
					<div dojoType="dijit.MenuItem"  label="100" iconClass="toPageIcon"	onClick="pageSizeChange(this.label);"></div>
					<div dojoType="dijit.MenuItem"  label="noPage" iconClass="noPageIcon"	onClick="allpage();"></div>
		      </div><!--span dojoType="dijit.Tooltip" connectId="668"></span-->
        </div>
		    <div id="669" dojoType="dijit.form.myDropDownButton" iconClass="pageStyleIcon"><span>pageStyle</span>
  			   <div dojoType="dijit.Menu">
  				 <div dojoType="dijit.MenuItem"  iconClass="rowIcon"		label="row"	onClick="pageStyle(this.label);"></div>
  				 <div dojoType="dijit.MenuItem"  iconClass="colIcon"		label="col"	onClick="pageStyle(this.label);"></div>
		    </div></div>
     </div></div>  
 </div>
</body></html>
